package com.kpmg.datalake.common.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 日期工具类
 *
 * @author user
 */
public class DateUtils {

  public static final String HHMMSS = "HHmmss";
  public static final String HH_MM_SS = "HH:mm:ss";
  public static final String YYYYMMDD = "yyyyMMdd";
  public static final String YYYY_MM_DD = "yyyy-MM-dd";
  public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
  public static final String YYYYMMDDHHMMSSSSS = "yyyyMMddHHmmssSSS";
  public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";


  private DateUtils() {

  }

  public static int getTheMonth(int year, int month) {
    Calendar instance = Calendar.getInstance();
    instance.clear();
    instance.set(Calendar.YEAR, year);
    instance.set(Calendar.MONTH, month - 1);
    instance.roll(Calendar.DATE, -1);
    return instance.get(Calendar.DATE);
  }

  public static String format(Date date) {
    return format(date, YYYY_MM_DD);
  }

  public static String format(Date date, String pattern) {
    if (date == null) {
      return null;
    }
    if (pattern == null) {
      return format(date);
    }
    return new SimpleDateFormat(pattern).format(date);
  }

}
